package com.ruoyi.web.controller.memberManagement;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PointsRedemptionRule;
import com.ruoyi.system.service.IPointsRedemptionRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分抵现规则（存储积分抵扣现金的规则）Controller
 *
 * @author ruoyi
 * @date 2025-05-16
 */
@Api(tags="积分抵现规则")
@RestController
@RequestMapping("/system/pointsRedemptionRule")
public class PointsRedemptionRuleController extends BaseController
{
    @Autowired
    private IPointsRedemptionRuleService pointsRedemptionRuleService;

    /**
     * 查询积分抵现规则列表
     */
    @ApiOperation("查询积分抵现规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PointsRedemptionRule pointsRedemptionRule)
    {
        startPage();
        List<PointsRedemptionRule> list = pointsRedemptionRuleService.selectPointsRedemptionRuleList(pointsRedemptionRule);
        return getDataTable(list);
    }

    /**
     * 导出积分抵现规则列表
     */
    @ApiOperation("导出积分抵现规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "积分抵现规则（存储积分抵扣现金的规则）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsRedemptionRule pointsRedemptionRule)
    {
        List<PointsRedemptionRule> list = pointsRedemptionRuleService.selectPointsRedemptionRuleList(pointsRedemptionRule);
        ExcelUtil<PointsRedemptionRule> util = new ExcelUtil<PointsRedemptionRule>(PointsRedemptionRule.class);
        util.exportExcel(response, list, "积分抵现规则（存储积分抵扣现金的规则）数据");
    }

    /**
     * 获取积分抵现规则详细信息
     */
    @ApiOperation("获取积分抵现规则详细信息")
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointsRedemptionRuleService.selectPointsRedemptionRuleById(id));
    }

    /**
     * 新增积分抵现规则列表
     */
    @ApiOperation("新增积分抵现规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "积分抵现规则（存储积分抵扣现金的规则）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsRedemptionRule pointsRedemptionRule)
    {
        return toAjax(pointsRedemptionRuleService.insertPointsRedemptionRule(pointsRedemptionRule));
    }

    /**
     * 修改积分抵现规则列表
     */
    @ApiOperation("修改积分抵现规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "积分抵现规则（存储积分抵扣现金的规则）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsRedemptionRule pointsRedemptionRule)
    {
        return toAjax(pointsRedemptionRuleService.updatePointsRedemptionRule(pointsRedemptionRule));
    }

    /**
     * 删除积分抵现规则列表
     */
    @ApiOperation("删除积分抵现规则列表")
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "积分抵现规则（存储积分抵扣现金的规则）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsRedemptionRuleService.deletePointsRedemptionRuleByIds(ids));
    }
}
